#include "Timer.h"

namespace lib3dw
{
	Timer::Timer()
	{
		#ifdef WIN32
		QueryPerformanceFrequency(&frequency); 
		#endif
	}
	
	Timer::~Timer()
	{
	}

	void Timer::Start()
	{
		#ifdef WIN32
		QueryPerformanceCounter(&startTime);
		#endif
		
		#ifdef __APPLE__
		struct timeval tv;
		gettimeofday(&tv,NULL);
		startTime = tv2micro(tv);
		#endif
	}

	double Timer::Stop()
	{
		#ifdef WIN32
		QueryPerformanceCounter(&endTime);
		return (double)(endTime.QuadPart-startTime.QuadPart)/(double)frequency.QuadPart *(double)1000.0;
		#endif

		#ifdef __APPLE__
		struct timeval tv;
		gettimeofday(&tv,NULL);
		endTime = tv2micro(tv);
		
		long long int td = endTime - startTime;
		return (((double)td) / N_MICROSEC_FLOAT) * 1000.0;
		#endif
	}	
}